import pygame.font
from Gun import Gun
from pygame.sprite import Group


class Score():

    def __init__(self, screen, stats):
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.stats = stats
        self.text_color = (166,230,29)
        self.font = pygame.font.SysFont('Arial', 24)
        self.text_image_score()
        self.image_record()
        self.lives_img()

    def text_image_score(self):

        self.image_score = self.font.render(str(self.stats.score), True, self.text_color, (0,0,0))
        self.score_rect = self.image_score.get_rect()
        self.score_rect.left = self.screen_rect.left + 40
        self.score_rect.top = self.screen_rect.top + 20

    def image_record(self):
        self.img_record = self.font.render(str(self.stats.record), True, self.text_color, (0,0,0))
        self.img_record_rect = self.img_record.get_rect()
        self.img_record_rect.right = self.screen_rect.right - 40
        self.img_record_rect.top = self.screen_rect.top + 20

    def lives_img(self):
        'lives count'
        self.lives = Group()
        for e in range(self.stats.lives):
            live_img = Gun(self.screen)
            live_img.rect.x = 15 + (e * live_img.rect.width) + 100
            live_img.rect.y = 20
            self.lives.add(live_img)

    def show(self):
        "Прорисовка счета"
        self.screen.blit(self.image_score, self.score_rect)
        self.screen.blit(self.img_record, self.img_record_rect)
        self.lives.draw(self.screen)
